<%@ taglib uri="/tags/struts-bean" prefix="bean"%>
<%@ taglib uri="/tags/struts-html" prefix="html"%>
<%@ taglib uri="/tags/struts-logic" prefix="logic"%>
<%@ taglib uri="/tags/core" prefix="c"%>
<%@ taglib uri="/tags/fmt" prefix="fmt"%>
<%@ taglib uri="/WEB-INF/tld/security.tld" prefix="s" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>

	function validateForm(){
	   var errorLen  = '';
	   amount = document.getElementById("amount");
	   if(amount.value == "" ){
			errorLen = '<bean:message key="error.creditlinebalance.enter.amount"/>\n';	   			
	   }else{
			if(amount.value == 0){
				errorLen = '<bean:message key="error.creditlinebalance.enter.amount"/>\n';
			}
	   }
	   return errorLen; 	
	 }

	function submitForm(action){			
		var form = document.getElementById('mainForm');
	    form.action = action;
	    var amount = document.getElementById('amount');
	    amount.value = amount.value.replace(/,/g, "");
	    if(action != 'goBuildPeriods.do'){
		    var errors = validateForm();
	   		if( errors == '' ){
	   			form.submit();
	   		}else{
	  			alert('Errores :  \n' + errors);
	   		}
	    }else{
	    	form.submit();
	    }
	}
</script>

</head>
<html:form action="/goCreditLineBalance" styleId="mainForm">
<body>
<fieldset style="width:700px;"><legend ><bean:message key="label.creditline.balance.creditline"/></legend>
<table width="700px" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
  <tr>
    <td class="etiqueta"><bean:message key="label.creditline.balance.consolidatedCreditLine"/></td>
    <td class="etiqueta_campo"><bean:write name="CreditLineBalanceForm" property="view.limit" format="$#,###,##0.0000"/>&nbsp;USD</td>
    <td class="etiqueta_campo">
    (<bean:write name="CreditLineBalanceForm" property="view.outOfCredit" format="###,##0"/>%&nbsp;
    <bean:write name="CreditLineBalanceForm" property="view.exceededLimit" format="$#,###,##0.0000"/>)</td>
  </tr>
</table>
</fieldset>
<br/>

<table  cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
  <tr>
    <td class="etiqueta"><bean:message key="label.creditline.balance.initialperiod"/></td>
    <td class="etiqueta_campo">
       	<html:select property="initPeriodId" styleClass="campo_texto">
          		<html:optionsCollection name="CreditLineBalanceForm" property="listPeriods" value="monthPeriodId" label="label"/>
       	</html:select>      
       </td>
    <td class="etiqueta"><bean:message key="label.creditline.balance.finalperiod"/></td>
    <td class="etiqueta_campo">
       	<html:select property="finishPeriodId" styleClass="campo_texto">
          		<html:optionsCollection name="CreditLineBalanceForm" property="listPeriods" value="monthPeriodId" label="label"/>
       	</html:select>    
	</td>
    <td  class="etiqueta_campo"><input type="submit" name="Submit" value="..." class="boton_short" onclick="submitForm('goBuildPeriods.do')" /></td>
  </tr>
</table>
<br/>
<div style="width:1000px; overflow-x:scroll;overflow:moz-scrollbars-horizontal" >

<table width="1000px" cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
 <tr bgcolor="white">
 <td class="etiqueta" width="100px"><bean:message key="label.creditline.balance.initialperiod"/></td>
 <logic:notEmpty name="CreditLineBalanceForm" property="balances">
 <logic:iterate id="balance" name="CreditLineBalanceForm" property="balances" indexId="int_i">
 	<td class="etiqueta" nowrap="true">
 	  <bean:write name="balance" property="label" />
 	 </td> 	
 </logic:iterate>
 </logic:notEmpty>
 <logic:empty name="CreditLineBalanceForm" property="balances">
 	<td class="etiqueta_campo">&nbsp;</td>
 </logic:empty>
 </tr>  
 <tr bgcolor="white">
    <td class="etiqueta"><bean:message key="label.creditline.balance.balance"/></td>
     <logic:notEmpty name="CreditLineBalanceForm" property="balances">
 		<logic:iterate id="balance" name="CreditLineBalanceForm" property="balances" indexId="int_i">
 		<td class='overdrawn<bean:write name="balance" property="overDrawn"/>' >
			<logic:equal name="balance" property="balanceEmpty" value="false">
			 	<logic:equal name="balance" property="balance" value="0">
 					&nbsp;
 				</logic:equal>
			 	<logic:notEqual name="balance" property="balance" value="0">
 					<bean:write name="balance" property="balance" format="$#,###,##0.0000" />
 				</logic:notEqual> 				
 				
 			</logic:equal>
 			<logic:notEqual name="balance" property="balanceEmpty" value="false">
 			  &nbsp;
 			</logic:notEqual> 	  	
 	 	</td> 	
 	</logic:iterate>
 	
 	</logic:notEmpty>
 	 
 	 <logic:empty name="CreditLineBalanceForm" property="balances">
 		<td class="etiqueta_campo">&nbsp;</td>
	 </logic:empty> 	
 	
  </tr>
  <tr bgcolor="white">
    <td class="etiqueta"><bean:message key="label.creditline.balance.preapplying"/></td>    
     <logic:notEmpty name="CreditLineBalanceForm" property="balances">
 		<logic:iterate id="balance" name="CreditLineBalanceForm" property="balances" indexId="int_i">
 		<td class='overdrawn<bean:write name="balance" property="overDrawn"/>'>
			<logic:equal name="CreditLineBalanceForm" property="pre" value="true" >
			  <logic:equal name="balance" property="monthlyPeriodApplied" value="true" >			      			  
 				<bean:write name="CreditLineBalanceForm" property="amount" format="$#,###,##0.0000" />
 			  </logic:equal>
 			</logic:equal>
 	 	</td> 	
 	</logic:iterate> 	
 	</logic:notEmpty>
 	
 	 <logic:empty name="CreditLineBalanceForm" property="balances">
 		<td class="etiqueta_campo">&nbsp;</td>
	 </logic:empty> 

  </tr>
 
   <tr bgcolor="white" >
	    <td class="etiqueta_campo" colspan='<bean:write name="CreditLineBalanceForm" property="listPeriodsSize"  />' >&nbsp;</td>

   </tr> 
  <tr bgcolor="white">
    <td class="etiqueta"><bean:message key="label.creditline.balance.available"/></td>
     <logic:notEmpty name="CreditLineBalanceForm" property="balances">
 		<logic:iterate id="balance" name="CreditLineBalanceForm" property="balances" indexId="int_i">
 		<td class='overdrawn<bean:write name="balance" property="overDrawn"/>' >
			<bean:write name="balance" property="available" format="$#,###,##0.0000" />
 	 	</td> 	
 		</logic:iterate>
 	</logic:notEmpty>
 	 
 	 <logic:empty name="CreditLineBalanceForm" property="balances">
 		<td class="etiqueta_campo">&nbsp;</td>
	 </logic:empty> 
 	
  </tr>
  
</table>
</div>

<br/>
<table width="700px" style="border-style:solid; border-width:1px; border-color: #cacaca" cellspacing="1">
  <tr>
    <td><fieldset><legend><bean:message key="label.creditline.balance.recordmovement"/></legend>

      &nbsp;
      <table cellpadding="2" cellspacing="1" border="0" bgcolor="#CCCCC0">
        <tr>
          <td class="etiqueta"><bean:message key="label.creditline.balance.initialperiod"/></td>
          <td class="etiqueta_campo">
          	<html:select property="subInitPeriodId" styleClass="campo_texto">
          		<html:optionsCollection name="CreditLineBalanceForm" property="subListPeriods" value="monthPeriodId" label="label"/>
          	</html:select>
          </td>
        </tr>
        <tr>
          <td class="etiqueta"><bean:message key="label.creditline.balance.finalperiod"/></td>
          <td class="etiqueta_campo">
	      	<html:select property="subFinishPeriodId" styleClass="campo_texto">
          		<html:optionsCollection name="CreditLineBalanceForm" property="subListPeriods" value="monthPeriodId" label="label"/>
          	</html:select>            
          	</td>
        </tr>
        <tr>
          <td class="etiqueta"><bean:message key="label.creditline.balance.amount"/></td>
          <td class="etiqueta_campo">

 		 <!-- <input type="text" name="amount" value="<fmt:formatNumber pattern="###,###,##0.0000" type="number" maxFractionDigits="4" value="${amount}"/>" onkeydown="return (numeric(event, 1) && noPaste(event, this));" onkeyup="extractNumber(this,2,false);" size="15" maxlength="10" onfocus="this.select();" class="campo_texto_r"/> -->
		 <input type="text" name="amount" value="<fmt:formatNumber pattern="###,###,##0.0000" type="number" maxFractionDigits="4" value="${CreditLineBalanceForm.amount}"/>" class="columnanumero" onclick="this.focus()" id="amount" style="width:110px" onkeyup="extractNumber(this,4,true);"/>
          </td>
        </tr>
        <tr>
          <td align="right" colspan="2" class="etiqueta_campo">
          <br/>
          <input align="right" type="button" name="Submit2" onclick="submitForm('goApplyAmountToPeriods.do')" class="boton" value="<bean:message key="button.creditline.balance.preapply"/>">
          </td>
        </tr>
      </table>
      	</fieldset>
      </td>
    <td valign="top"><fieldset><legend><bean:message key="label.creditline.balance.lastmovements"/></legend>
	<table cellpadding="2" width="100%" cellspacing="1" border="0" bgcolor="#CCCCC0">
  		<tr>
          <td class="titulocolumna"><bean:message key="label.creditline.balance.date"/></td>
          <td class="titulocolumna"><bean:message key="label.creditline.balance.amount"/></td>
          <td class="titulocolumna"><bean:message key="label.creditline.balance.period"/></td>
  		</tr>
  		<logic:present name="CLB_RECENTS">

  			<logic:iterate id="recent" name="CLB_RECENTS" indexId="int_i" scope="session" >
  				<tr class="<%=((int_i.intValue()%2)==0?"columnadatoPar":"columnadatoNon")%>">
  					<td><bean:write name="recent" property="date" format="dd/MM/yyyy hh:mm:ss"/></td>
  					<td class="columnanumero">
  					<fmt:formatNumber maxFractionDigits="4" pattern="###,###,##0.0000" value="${recent.amount}"/>
  					</td>

  							 
  					<td><bean:write name="recent" property="rangePeriod"/></td>  					
				</tr>  				
  			</logic:iterate>
  		</logic:present>  		

	</table>

	</fieldset>&nbsp;</td>
  </tr>
</table>

<br/>
<table width="200px" style="border-style:solid; border-width:1px; border-color: #cacaca" cellspacing="1">
  <tr>
 
    <td><div align="center">
    	<s:entidad nombreCortoEnt="SAVE" permiso="ADMINISTRACION" nombreCortoMod="DRAFTDIS" nombreCortoSub="BALANCE">
        	<input type="button" name="Submit3" class="boton" onclick="submitForm('updateCreditlineBalances.do')" value="<bean:message key="label.credit.line.save"/>">
        </s:entidad>	
      </div></td>
     <td>
      	<div align="center">
  			<input type="button" value="<bean:message key="label.common.cancel"/>"
						onclick="location.href = 'welcome.do';" class="boton" />
		</div>
	</td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html:form>
<script>
cleanNumber(document.getElementById('amount'));
</script>

</html>
